import { getRecommendRequest } from '../../../api/request'
import * as actionTypes from './constants'
import { Dispatch } from 'redux'
import { IRecommendList } from './reducer'

export const changeRecommendList = (data:IRecommendList) => ({
    type: actionTypes.CHANGE_RECOMMEND_LIST,
    data 
})

export const changeEnterLoading = (data:boolean) => ({
    type: actionTypes.CHANGE_LOADING,
    data
})

export const changeDianzan = (id:number) => ({
    type: actionTypes.CHANGE_DIANZAN,
    id
})

export const getRecommendList = () => {
    return (dispatch: Dispatch) => {
        getRecommendRequest()
            .then(data => {
                console.log(data.data)
                dispatch(changeRecommendList(data.data))
                dispatch(changeEnterLoading(false))
            }).catch(() => {
                console.log("推荐装修房屋数据传输错误");
            });
    }
}